home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11653 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: nova.umuc.edu!not-for-mail
  2. From: cm140c31@nova.umuc.edu (Robert Rodgers)
  3. Newsgroups: comp.lang.c++
  4. Subject: Is there an asynchronous cin.peek()?
  5. Date: 15 Mar 1996 11:02:05 -0500
  6. Organization: University of Maryland University College
  7. Message-ID: <4ic49t$ivb@nova.umuc.edu>
  8. NNTP-Posting-Host: nova.umuc.edu
  9.  
  10. I'm writing a small utility that needs to decide at runtime whether to 
  11. read re-directed input (e.g., x < data.txt) or read the same input from a 
  12. data file.  I need to to compile clean, using the standard, portable 
  13. libraries.
  14.  
  15. The problem I'm encountering is, I'm not used to using cin/cout, and I 
  16. can't find a way to do an asychronous peek at the input stream.  For example:
  17.  
  18. char x;
  19. if(EOF != (x = cin.peek())){
  20.     cout << "x is going to be '" << x << "'.\n";
  21. }
  22.  
  23. The problem is that if you compile this and run it *without* redirected 
  24. input, it pauses until it gets some (any) input.  I don't want this -- I 
  25. want to check of the stream is empty, and if it's empty, skip ahead to 
  26. the file parser.  cin.peek() doesn't return until something enters the 
  27. stream.
  28.  
  29. Any help would be appreciated.
  30.  
  31.  
  32.